package cn.wen.eeayjoke.config;

import android.text.TextUtils;

import cn.wen.base.util.AppConfig;

/**
 * URL管理的对象
 */

public class URLConfig {
    private static volatile URLConfig mInstance;
    // H5的一个URL===========================================
    private static String H5_ONLINE = "http://m.car-house.cn/wx/#";
    private static String H5_TEST = "http://m.car-house.cn/test/#";
    // PHP的一个URL===========================================
    private static String PHP_ONLINE = "http://app.car-house.cn/app.php";
    private static String PHP_TEST = "http://192.168.1.226:80/app.php";
    /**
     * 默认的BaseURL
     */
    private String mBaseUrl;

    private URLConfig() {
        mBaseUrl = URLS.getURLS(0).getBaseUrl();
        // 如果是调试
        if (AppConfig.IS_DEBUG) {
            // 从缓存里面取
            String saveUrl = URLS.getSaveUrl();
            if (!TextUtils.isEmpty(saveUrl)) {
                mBaseUrl = saveUrl;
            }
        }
    }

    public static URLConfig getInstance() {
        if (mInstance == null) {
            synchronized (URLConfig.class) {
                if (mInstance == null) {
                    mInstance = new URLConfig();
                }
            }
        }
        return mInstance;
    }


    /**
     * 获取后台的BaseUrl
     */
    public String baseUrl() {
        return mBaseUrl;
    }

    /**
     * 获取PhpUrl
     */
    public String phpUrl() {
        return isOnline() ? PHP_ONLINE : PHP_TEST;
    }

    /**
     * 获取H5Url
     */
    public String h5Url() {
        return isOnline() ? H5_ONLINE : H5_TEST;
    }

    /**
     * 是不是线上
     */
    private boolean isOnline() {
        return URLS.getURLS(0).getBaseUrl().equals(mBaseUrl);
    }

}
